#include<bits/stdc++.h>
#define lowbit(x) ((x)&-(x))
using namespace std;
int n,m;
int t[50011];
void add(int p,int x)
{
	if(!p)
		return;
	while(p <= n)
		t[p] += x,p += lowbit(p);
}
int ask(int p)
{
	int res = 0;
	while(p)
		res += t[p],p -= lowbit(p);
	return res;
}
vector<pair<int,int> > v[50011];
set<int> S[50011];int d[50011];
int a[50011],dui[50011];
int mx[50011];
vector<int> e[50011];
int fa[50011];
void Merge(int& x,int y,int p)
{
	if(S[x].size() < S[y].size())
		swap(x,y);
	for(auto i:S[y])
	{
		auto k = S[x].lower_bound(i);
		if(k != S[x].begin())
		{
			auto o = k;
			o--;
			v[i].push_back({p,*o});
		}
		if(k != S[x].end())
			v[*k].push_back({p,i});
	}
	for(auto i:S[y])
		S[x].insert(i);
}
void DFS(int p)
{
	S[d[p] = p].insert(dui[p]),v[dui[p]].push_back({p,dui[p]});
	for(auto i:e[p])
		DFS(i),Merge(d[p],d[i],p);
}
typedef struct{
	int l,r,id;
}QS;
bool cmp(QS A,QS B)
{
	return A.r < B.r;
}
QS q[50011];
int ans[50011];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	cin >> n >> m;
	for(int i = 2;i <= n;i++)
		cin >> fa[i],e[fa[i]].push_back(i);
	for(int i = 1;i <= n;i++)
		cin >> a[i],dui[a[i]] = i;
	DFS(1);
	for(int i = 1;i <= m;i++)
		cin >> q[i].l >> q[i].r,q[i].id = i;
	sort(q + 1,q + m + 1,cmp);
	for(int r = 1,i = 0;r <= n;r++)
	{
		for(auto i:v[r])
			add(mx[i.first],-1),add(mx[i.first] = max(mx[i.first],i.second),1);
		while(i < m && q[i + 1].r == r)
			i++,ans[q[i].id] = ask(r) - ask(q[i].l - 1);
	}
	for(int i = 1;i <= m;i++)
		cout << ans[i] << "\n";
	return 0;
}
